#include "stdafx.h"
#include "Tools.h"


CTools::CTools()
{
}


CTools::~CTools()
{
}


void CTools::DrawToBackground(int posx, int posy, IplImage *Bg, IplImage *img, int keyb, int keyg, int keyr)
{
	for (int i = 0; i < img->height; i++) {
		for (int j = 0; j < img->width; j++) {
			int b, g, r;
			b = CV_IMAGE_ELEM(img, uchar, i, j * 3 + 0);
			g = CV_IMAGE_ELEM(img, uchar, i, j * 3 + 1);
			r = CV_IMAGE_ELEM(img, uchar, i, j * 3 + 2);
			
			if (abs(b - keyb) <= 30 && abs(r - keyr) <= 30 && abs(g - keyg) <= 30)	continue;
			if (i + posy > Bg->height || i + posy < 0 || j + posx > Bg->width || j + posx < 0)	continue;
			CV_IMAGE_ELEM(Bg, uchar, i + posy, (j + posx) * 3 + 0) = b;
			CV_IMAGE_ELEM(Bg, uchar, i + posy, (j + posx) * 3 + 1) = g;
			CV_IMAGE_ELEM(Bg, uchar, i + posy, (j + posx) * 3 + 2) = r;
		}
	}

}
